<script type="text/javascript" src="<?=base_url()?>resource/js/layer/layer.js"></script>
<script>
    /**
     * 获取产品分类数据
     */
    function getProductClassData(num){
        var tid='';
        var bid='';
        var item={};
        var html="<option value=''>-请选择-</option>";
        switch (num){
            case 1:
                $('#brand_id').html(html);
                $('#model_id').html(html);
                tid=$('#categoryId').val();
                item={'tid':tid};
                break;
            case 2:
                $('#model_id').html(html);
                tid=$('#categoryId').val();
                bid=$('#brand_id').val();
                item={'tid':tid,'bid':bid};
                break;
            default :
                alert('参数异常');
                return false;
        }
        var load=layer.load(2);
        $.post("<?=blang_url('ajax/ajax/getProductClassAll')?>",item,function(data){
            if(data){
                layer.close(load);
                if(data==101){
                    alert('当前分类下没有任何数据');
                }else {
                    var productData = JSON.parse(data);
                    for (var i = 0; i < productData.length; i++) {
                        html += "<option value='" + productData[i]['sap_id'] + "'>" + productData[i]['name'] + "</option>";
                    }
                    switch (num) {
                        case 1:
                            $('#brand_id').html(html);
                            break;
                        case 2:
                            $('#model_id').html(html);
                            break;
                        default :
                            break;
                    }
                }
            }
        });
    }
</script>

<!--菜单 start-->
<?php $this->load->view('defaults/common/left');?>
<!--菜单 end-->
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
          <h1>基项管理</h1>
          <?=$this->breadcrumb->generateHTML();?>
        </div>
    </div>
    <div class="container-fluid">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title"><i class="fa fa-pencil"></i>新增</h3>
          </div>
          <div class="panel-body">
            <form class="form-horizontal" id="orderManageForm" action="" method="post" name="productform" autocomplete="off" data-options="novalidate:true">
                <div class="form-group">
                    <label class="col-sm-2 control-label"><label class="red">*</label>产品类型</label>
                    <div class="col-sm-10">
                      <select name="category" id="categoryId" onchange="getProductClassData(1)" class="form-control easyui-validatebox" data-options="required:true" <? if($post_type == "edit") echo 'disabled="disabled"'?>
                            <option value="">-请选择-</option>
                            <?php foreach ($categoryList as $rs):?>
                                <option value="<?=$rs['id'].'_'.$rs['sap_id']?>" <?=$optCategory[$rs['id']]?> >
                                    <?=$rs['name_ch']?>
                                </option>
                            <?php endforeach;?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">产品品牌</label>
                    <div class="col-sm-10">
                      <select class="form-control"  name="brand_id" id="brand_id" onchange="getProductClassData(2)" <? if($post_type == "edit") echo 'disabled="disabled"'?>>
                            <option value="">-请选择-</option>
                            <?php if($brandList){foreach($brandList as $bs){?>
                                <option value="<?=$bs['sap_id']?>" <?=$optBrand[$bs['sap_id']]?>><?=$bs['name']?></option>
                            <?php }}?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">产品型号</label>
                    <div class="col-sm-10">
                        <select class="form-control" name="model_id" id="model_id" <? if($post_type == "edit") echo 'disabled="disabled"'?>>
                            <option value="">-请选择-</option>
                            <?php if($modelList){foreach($modelList as $ms){?>
                                <option value="<?=$ms['sap_id']?>" <?=$optModel[$ms['sap_id']]?>><?=$ms['name']?></option>
                            <?php }}?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><label class="red">*</label>维修级别</label>
                    <div class="col-sm-10">
                        <select name="grade" class="form-control easyui-validatebox" data-options="required:true" <?=$post_type=='edit'?'disabled':''?>>
                            <?php foreach ($gradeList as $rs):?>
                                <option value="<?=$rs['id']?>" <?=$optGrade[$rs['id']]?> > <?=$rs['name_'.$curLang]?> </option>
                            <?php endforeach;?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><label class="red">*</label>中文名称</label>
                    <div class="col-sm-10">
                        <input type="text" name="name_ch" id="name_ch" value="<?=$repairItemFirst['name_ch']?>" class="form-control easyui-validatebox" data-options="required:true,validType:['length[0,50]']" />
                    </div>
                </div>
                 <div class="form-group">
                    <label class="col-sm-2 control-label"><label class="red">*</label>英文名称</label>
                    <div class="col-sm-10">
                        <input type="text" name="name_en" id="name_en" value="<?=$repairItemFirst['name_en']?>" class="form-control easyui-validatebox" data-options="required:true,validType:['length[0,50]']"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><label class="red">*</label>是否默认</label>
                    <div class="col-sm-10">
                        <label class="oms-radio">
                            <input type="radio" name="isDefault" value="0"  <?=$ckdIsDefault['0']?> class="easyui-validatebox" validType="radio['productform','isDefault']" />No
                        </label>
                        <label class="oms-radio">
                            <input type="radio" name="isDefault" value="1"  <?=$ckdIsDefault['1']?> class="easyui-validatebox" validType="radio['productform','isDefault']"/>Yes
                        </label>
                        <label style="color:#1872a2;">Note：拒绝报价收取此此维修项费用</label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><label class="red">*</label>基础费用</label>
                    <div class="col-sm-10">
                        <table class="c_c_tables style20170608" cellspacing="0">
                          <tbody>
                            <tr>
                                <td class="tableSubtitle equa even"></td>
                                <td class="tableSubtitle equa even">个人</td>
                                <td class="tableSubtitle equa even">商家</td>
                                <td class="tableSubtitle equa even">品牌</td>
                            </tr>
                            <?php foreach ($siteLaborList as $i=>$rs):?>
                             <tr class="basePriceC basePriceM">
                                <td class="tableSubtitle equa alignRight <?php if($i%2 == 0) echo 'odd';else echo 'even'; ?>"><?=$rs['name_ch']?>&nbsp;<?=$rs['currency']?></td>
                                <td class="equa"><input type="text" name="<?='individual_price'.$rs['point_id']?>" value="<?=$rs['individual_price']?>" class="easyui-validatebox" data-options="required:true,validType:['intOrFloat']"/></td>
                                <td class="equa"><input type="text" name="<?='merchant_price'.$rs['point_id']?>" value="<?=$rs['merchant_price']?>" class="easyui-validatebox" data-options="required:true,validType:['intOrFloat']"/></td>
                                <td class="equa"><input type="text" name="<?='brand_price'.$rs['point_id']?>" value="<?=$rs['brand_price']?>" class="easyui-validatebox" data-options="required:true,validType:['intOrFloat']"/></td>
                            </tr>
                            <?php endforeach;?>
                            <tr>
                                <td class="equa"></td>
                                <td class="equa" colspan="3">
                                    <a href="#" class="synOperation btn btn-oms"><i class="fa fa-refresh"></i>&nbsp;同步第一行</a>
                                </td>
                            </tr>
                          </tbody>
                        </table>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-10">
                        <input type="hidden" name="id" value="<?=$repairItemFirst['id']?>">
                        <input class="btn btn-primary" type="submit" value="<?=lang('public_tj')?>" name="submits" style="padding:8px 45px;"/>
                    </div>
                </div>
            </form>
          </div>
        </div>
    </div>
    
    <script>
    $(function(){
        /*验证中文名和英文名是否已经使用*/
        function verifyName(){
            var tid=$('#categoryId').val();
            var bid=$('#brand_id').val();
            var mid=$('#model_id').val();
            var name_ch=$('#name_ch').val();
            var name_en=$('#name_en').val();
            var param={'tid':tid,'bid':bid,'mid':mid,'name_ch':name_ch,'name_en':name_en};
            var flag = false,loading = layer.load(2),_post_type = '<?=$post_type?>';
            if(_post_type == "edit"){
                layer.close(loading);
                flag = true;
            }else{
                $.ajax({ 
                type : "post",  
                url : "<?=blang_url('ajax/ajax/verifyRepairItemName')?>",  
                data : param,  
                async : false,  
                success : function(data){
                    layer.close(loading);
                    switch (data){
                        case '1':
                            layer.msg("维修项中文名称重复！", {
                                  skin:'layui-msg-error',
                                  time:1500
                             });
                            break;
                        case '2':
                            layer.msg("维修项英文名称重复！", {
                                  skin:'layui-msg-error',
                                  time:1500
                             });
                            break;
                        case '3':
                            flag = true;
                            break;
                        default :
                            layer.msg("系统未知错误", {
                                  skin:'layui-msg-error',
                                  time:1500
                             });
                            break
                    }
                }  
             }); 
            }
            return flag;
        }

        $('#orderManageForm').form({
            onSubmit:function(){
                var isValid = $(this).form('enableValidation').form('validate');
                if(isValid){
                   if(verifyName()){
                        $.ajax({
                            type: "POST",
                            url:'<?=blang_url('orders/Product_repair_item/'.$post_type)?>',
                            data: $('#orderManageForm').serialize()+"&submits=tijiao",
                            success: function (data) {
                               
                                layer.msg("提交成功", {
                                      skin:'layui-msg-success',
                                      time:1500,
                                 },function(){
                                    window.location.href='<?=blang_url('orders/Product_repair_item')?>';
                                 });
                            },
                            error: function(data) {
                                layer.msg("提交失败", {
                                      skin:'layui-msg-error',
                                      closeBtn:1,
                                      time:1500
                                 });
                             }
                        });
                   }
                }
                return false;
            }
        });

    });
</script>

</div>




